package com.jonas.schart;

import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;

import com.jonas.jgraph.graph.MJcoolGraph;
import com.jonas.jgraph.models.Jchart;

import java.security.SecureRandom;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

/**
 * 第3个我自定义简单使用
 */
public class testActivity extends AppCompatActivity {
    private int chartNum = 14;
    private MJcoolGraph mLineChar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        mLineChar = (MJcoolGraph) findViewById(R.id.sug_recode_line);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });
        // mLineChar.setShaderAreaColors(Color.parseColor("#123456"),Color.parseColor("#fdfeab")); //设置阴影渐变
        mLineChar.setPaintShaderColors(Color.RED, Color.parseColor("#E79D23"),
                Color.parseColor("#FFF03D"), Color.parseColor("#A9E16F"), Color.parseColor("#75B9EF"));

        List<Jchart> lines = new ArrayList<>();
        for (int i = 0; i < chartNum; i++) {
            Jchart jchart = new Jchart(i, new SecureRandom().nextFloat() * 10 + 15); //(float) 0
            jchart.setShowMsg(new DecimalFormat("##").format(jchart.getUpper()) + "kwh/$" + "0.00");
            lines.add(jchart);
            //            lines.add(new Jchart(10,new SecureRandom().nextInt(50) + 15,"test", Color.parseColor("#b8e986")));
        }
        lines.get(1).setUpper(0);
        lines.get(2).setUpper(30);
        mLineChar.feedData(lines);
    }

}
